﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.IBLL;
using Hr.IDAL;
using Hr.DALContainer;
using Hr.Model;
using System.Data.Entity;
using Hr.DAL;

namespace Hr.BLL
{
    public class ArticleService
    {
        //创建EF对象
        private DbContext db = DbContextFactory.Create();

        //引入DAL层
        protected ArticleDAL Rdl = new ArticleDAL();

        //BLL层核心代码

        #region 新闻管理页面数据

        /// <summary>
        /// 新闻管理页面数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>新闻管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/22</create>
        /// <updata>null</updata>
        public Dictionary<string, object> ArticleList(int page, int limit)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ArticleList",Rdl.ArticleList().Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.ArticleList().Count() }
            };
            return dt;
        }

        #endregion

        #region 根据Title查询新闻管理页面数据

        /// <summary>
        /// 根据Title查询新闻管理页面数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>新闻管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/22</create>
        /// <updata>null</updata>

        public Dictionary<string, object> TitleSelectArticleList(int page, int limit, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"ArticleList",Rdl.TitleSelectArticleList(Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Rdl.TitleSelectArticleList(Title).Count() }
            };
            return dt;
        }

        #endregion

        #region 根据pk_Article删除新闻管理页面数据

        /// <summary>
        /// 根据pk_Article删除新闻管理页面数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns>新闻管理</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/22</create>
        /// <updata>null</updata>

        public bool DelArticleList(int pk_Article)
        {
            Rdl.DelArticleList(pk_Article);

            return Rdl.SaveChanges();
        }

        #endregion

        #region 类型和状态下拉框
        /// <summary>
        /// 下拉框绑定
        /// </summary>
        /// <param name="id">类型和状态下拉框</param>
        /// <returns>修改和增加页面里的下拉框</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/22</create>
        /// <updata>null</updata>

        public IEnumerable<Sys_TypeID> SelectTypeBinding()
        {
            return Rdl.SelectTypeBinding();
        }
        public IEnumerable<Sys_StatusID> SelectStatusBinding()
        {
            return Rdl.SelectStatusBinding();
        }
        #endregion

        #region 新闻查看 包括记录点击数
        /// <summary>
        /// 新闻查看 包括记录点击数
        /// </summary>
        /// <param name="id">pk_Article</param>
        /// <returns>新闻查看</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/24</create>
        /// <updata>null</updata>

        public object ArticleDataBinding(int pk_Article)
        {
            return Rdl.ArticleDataBinding(pk_Article);
        }

        #endregion

        #region 新闻管理修改添加
        /// <summary>
        /// 新闻管理修改添加
        /// </summary>
        /// <param name="id">pk_Article</param>
        /// <returns>修改和增加页面</returns>
        /// <author>刘俊杰</author>
        /// <create>2020/8/22</create>
        /// <updata>null</updata>
        public Article_List GetModels(int pk_Article)
        {
            return Rdl.GetModels(pk_Article);
        }
        public bool EditArticleList(Article_List al, string type, int CreateUser)
        {
            Rdl.EditArticleList(al, type, CreateUser);
            return Rdl.SaveChanges();
        }
        #endregion
    }
}
